package com.cwnuzj.app.jokeworld.util;

import java.util.ArrayList;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.cwnuzj.app.jokeworld.form.JokeMessage;
import com.cwnuzj.app.jokeworld.form.Quote;

public class HtmlParser {
	public static ArrayList<JokeMessage> getLatestJokeMessages(Document document) {
		ArrayList<JokeMessage> messages = new ArrayList<JokeMessage>();
		// 找到对应的帖子
		Element messageElemente = document.select("div.newcontent").first();
		Elements liElements = messageElemente.select("li");
		for (Element temp : liElements) {

			Element link = temp.select("a").first();
			String title = link.text();
			String url = link.attr("abs:href");
			// 解析时间
			String time = temp.select("span").get(0).html();

			// 解析内容
//			Document contentDoc = null;
//			try {
//				contentDoc = Jsoup.connect(url).get();
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//			String content = contentDoc.select("span#text110").first().text();
//			String count = contentDoc.select("span.data").first().text();
//			Quote quote = new Quote(count, content);
			Quote quote = new Quote();
			
			JokeMessage message = new JokeMessage(title, quote, time, url);
			messages.add(message);
		}
		return messages;
	}

}
